/***********************************************************************
	filename: 	DaterTranslator.cpp
	created:	15/4/2012
	author:		4Ys
	
	purpose:	Implements a virtual class of translator from client to server
*************************************************************************/
#include"DaterTranslator.h"
namespace Dater
{
	Translator::Translator():_delimiter('\b'), _selectResultDelimiter('\t'), 
		linktosql(),_user("root"),_password("19920418"),_splitedOrder()
	{
		//split(_order, _delimiter, _splitedOrder);
		/* //check: 
		std::cout << "vector\nsize:  " << _splitedOrder.size() << "\n";;
		for(int i = 0; i != _splitedOrder.size(); i++)
			std::cout << _splitedOrder[i] << "\n";
		*/
	}

	void Translator::split(std::string const& order, char delimiter, std::vector<std::string>& splitedVector)
	{
		splitedVector.clear();

		if(order.size() == 0)
			return;

		std::string::size_type pos = 0, pre_pos = 0;

		while((pos = order.find_first_of(delimiter, pos)) != std::string::npos)
		{
			splitedVector.push_back(order.substr(pre_pos, pos - pre_pos));
			pre_pos = ++pos;
		}

		splitedVector.push_back(order.substr(pre_pos, pos - pre_pos));

	}

	bool Translator::ifRequest()
	{
		return _ifRequest;
	}
}